home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / tex / nobit71.zip / NOBIT71.ASM < prev    next >
Assembly Source File  |  1988-12-01  |  6KB  |  256 lines

  1. TITLE    NOBIT7    10-19-88    [12-1-88]
  2. ;NOBIT7.COM disassembled via ASMGEN.
  3. ;
  4. ;(Silly that a wee little program, doing such a wee simple little thing,
  5. ; shouldn't be released with source code.)
  6. ;Tweaked to within an inch of its life (mostly in lower case).
  7. ;Not significantly faster, but carved a couple hundred bytes out of it.
  8. ;
  9. ;All rights remain with the author, Ray Johns.
  10. ;David Kirschbaum
  11. ;Toad Hall
  12. ;kirsch@braggvax.ARPA
  13.  
  14.  
  15. LF    EQU    0AH
  16. CR    EQU    0DH
  17. ;
  18. CSeg    SEGMENT
  19.     ASSUME DS:CSeg, SS:CSeg ,CS:CSeg ,ES:CSeg
  20.     org    80H
  21. cmdlen    label    byte            ;PSP command line
  22.  
  23.     ORG    100H
  24.  
  25. NoBit7    proc    near
  26.     JMP    Start            ;skip over data
  27.  
  28. inHandle    dw    0
  29. outHandle    dw    0
  30.  
  31. logo    DB    'NOBIT7 - 1.01 - Copyright (c) 1988, Ray Johns',CR,LF,LF
  32.     DB    'Input file : '
  33. LOGOLEN    =    $ - logo
  34.  
  35. openerr    DB    CR,LF,'Cannot open file',CR,LF
  36. LEN18C    =    $ - openerr
  37.  
  38. closerr    DB    CR,LF,'Cannot close file',CR,LF
  39. LEN1A1    =    $ - closerr
  40.  
  41. noinput    DB    CR,LF,'No input file',CR,LF
  42. LEN1B7    =    $ - noinput
  43.  
  44. workmsg    DB    CR,LF,'Working '
  45. LEN1C9    =    $ - workmsg
  46.  
  47. ioerr    DB    CR,LF,'I/O error',CR,LF
  48. LEN1D4    =    $ - ioerr
  49.  
  50. donemsg    DB    CR,LF,'Complete',CR,LF
  51. LEN1E2    =    $ - donemsg
  52.  
  53. kbdbuff    DB    41H    ;buffer for user keyboard input
  54.                 ;(41H is max bytes to be input)
  55.  
  56. bufflen    DB    0
  57. bufftxt    DB    42H DUP(0)
  58.  
  59. NoBit7    endp
  60.  
  61.  
  62. Start    proc    near
  63.     CLD
  64.     MOV    DX,OFFSET logo        ;'NOBIT7..' logo
  65.                     ;plus 'Input: ' msg
  66.     MOV    CX,LOGOLEN        ;msg length
  67.     CALL    Write            ;display msg
  68.  
  69.     mov    si,offset cmdlen    ;start at PSP command line
  70.     cld                ;insure fwd
  71.     lodsb                ;snarf cmdline length
  72.     or    al,al            ;no PSP command?
  73.     jz    Need_FileName        ;none, go prompt for one
  74.  
  75.     mov    bx,200DH        ;BH=space,BL=CR
  76.     mov    di,offset bufftxt    ;move name into internal buffer
  77.     mov    dx,di            ;remember that start
  78. NameLup:
  79.     lodsb                ;grab cmdline char
  80.     cmp    al,bh            ;space?
  81.     je    NameLup            ;yep, gobble them
  82.     cmp    al,bl            ;CR (terminator)?
  83.     je    Name_Done        ;yep, done
  84.     stosb                ;stuff in internal buffer
  85.     jmp    NameLup            ;keep going
  86.  
  87. Name_Done:
  88.     mov    byte ptr [di],0        ;AsciiZ the name
  89.  
  90.     sub    di,dx            ;start - end
  91.     mov    cx,di            ; = name length
  92.     CALL    Write            ;display filename
  93.     JMP    SHORT    Skp271        ;skip over user input
  94.  
  95. ;Come here if no target file on command line.
  96. Need_FileName:
  97.     CALL    Get_User_Input        ;prompt user for filename (may die)
  98.  
  99. Skp271:    CALL    Open_Files        ;try to open the file(s) (may die)
  100.     CALL    Process_File        ;do the conversion (may die)
  101.     CALL    Close_Files        ;close up (may die)
  102.     JMP    Completed        ;say completed, terminate
  103. Start    endp
  104.  
  105.  
  106. ;Call if no target filename on the PSP command line.  Called once
  107. Get_User_Input    proc    near
  108.     MOV    DX,OFFSET kbdbuff    ;the buffer
  109.     mov    si,dx            ;point SI there also
  110.     MOV    AH,0AH            ;buffered kbd input
  111.     INT    21H
  112.     inc    si            ;bump SI to the length byte
  113.     lodsb                ;snarf length byte, bump SI
  114.     or    al,al            ;anything in length byte?
  115.     JZ    NoInput_Error        ;nope, error msg, die
  116. ;SI now points to first char of input text
  117.      xor    ah,ah            ;clear msb
  118.      add    si,ax            ;point to the end
  119.      mov    [si],ah            ;stuff AsciiZ terminator
  120.      RET
  121.  
  122. NoInput_Error:
  123. ;User made a target filename null entry after the prompt.
  124. ;Message and die.
  125.     MOV    DX,OFFSET noinput    ;'No input file'
  126.     MOV    CX,LEN1B7        ;msg length
  127.     MOV    AL,0DH            ;error
  128.     JMP    Terminate        ;terminate, ERRORLEVEL 0DH
  129. Get_User_Input    endp
  130.  
  131.  
  132. Open_Files    proc    near        ;called once
  133.     MOV    DX,OFFSET bufftxt    ;pointer to AsciiZ filename
  134.     MOV    AX,3D00H        ;open file for input (read only)
  135.     INT    21H
  136.     JB    Open_Error        ;failed
  137.  
  138.     MOV    inHandle,AX        ;save the input handle
  139.  
  140. ;DX still points to Asciiz filename .. we're gonna open it TWICE ..
  141. ;once for read and once for write .. ugh ..
  142.     MOV    AX,3D01H        ;open SAME file for output (write only)
  143.     INT    21H            ;(DX is unchanged)
  144.     JB    Open_Error        ;failed
  145.      MOV    outHandle,AX        ;save the output handle
  146.      RET
  147.  
  148. Open_Error:
  149.     MOV    DX,OFFSET openerr    ;'cannot open file'
  150.     MOV    CX,LEN18C        ;msg length
  151.     JMP    Terminate        ;terminate, ERRORLEVEL in AL
  152. Open_Files    endp
  153.  
  154.  
  155. Process_File    proc    near        ;called once
  156.     MOV    DX,OFFSET workmsg    ;'Working'
  157.     MOV    CX,LEN1C9        ;msg length
  158.     CALL    Write            ;display msg
  159.  
  160.     MOV    DX,OFFSET buff370    ;buffer just beyond code end
  161.                     ;(doesn't change)
  162. Lup2EC:
  163.     MOV    CX,0C800H        ;most of remaining code space
  164.     MOV    BX,inHandle        ;this handle
  165.     MOV    AH,3FH            ;read from file/device
  166.     INT    21H
  167.     JB    IoErr_End        ;failed, die with error msg
  168.  
  169. ;DOS returns bytes actually read in AX
  170.  
  171.     or    ax,ax            ;file end?
  172.     JZ    File_Eof        ;yep, return
  173.     mov    bx,ax            ;save bytes read in BX
  174.     inc    ax            ;bump in case it's odd
  175.     shr    ax,1            ;/2 for words
  176.     MOV    CX,AX            ;use as counter
  177.     MOV    SI,dx            ;start at file read buffer top
  178.     mov    ax,7F7FH        ;masking constant
  179. MaskLup:
  180.     AND    [SI],ax            ;mask both bytes to 7 bits
  181.     INC    SI            ;bump the pointer
  182.     inc    si            ;by words
  183.     LOOP    MaskLup            ;for all bytes read
  184.  
  185.     mov    cx,bx            ;restore orig bytes read
  186.     MOV    BX,outHandle        ;output handle
  187.     MOV    AH,40H            ;write to file/device
  188.     INT    21H            ;(DX is still unchanged)
  189.     JB    IoErr_End        ;write failed, msg and die
  190.  
  191.     mov    bx,dx            ;save DX a sec
  192.     MOV    AH,6            ;direct kbd/display/IO
  193.     MOV    DL,'.'            ;display a dot to show we're working
  194.     INT    21H
  195.     mov    dx,bx            ;restore DX buffer offset
  196.     JMP    Lup2EC            ;back for another buffer full
  197.  
  198. File_Eof:
  199.     RET
  200. Process_File    endp
  201.  
  202.  
  203. Close_Files    proc    near        ;called once
  204.     MOV    AH,3EH            ;close file handle
  205.     MOV    BX,inHandle        ;input file
  206.     INT    21H
  207.     JB    CloseErr_End        ;failed
  208.     MOV    AH,3EH            ;close file handle
  209.     MOV    BX,outHandle        ;output file
  210.     INT    21H
  211.     JB    CloseErr_End        ;failed
  212.     RET
  213. Close_Files    endp
  214.  
  215.  
  216. Shut_Down    proc    near        ;lump these together to be neat
  217.  
  218. CloseErr_End:
  219.     MOV    DX,OFFSET closerr    ;'cannot close file'
  220.     MOV    CX,LEN1A1        ;msg length
  221.     JMP    SHORT    Terminate    ;msg, terminate
  222.  
  223. IoErr_End:                ;jumped to twice
  224.     MOV    DX,OFFSET ioerr        ;'I/O Error'
  225.     MOV    CX,LEN1D4        ;msg length
  226.     JMP    SHORT    Terminate    ;msg, terminate
  227.  
  228. Completed:                ;jumped to once
  229.     MOV    DX,OFFSET donemsg    ;'Complete'
  230.     MOV    CX,LEN1E2        ;msg length
  231.     xor    al,al            ;ERRORLEVEL 0
  232.  
  233. Terminate:                ;jumped to 5 times
  234.     push    ax            ;save error value
  235.     call    Write            ;display msg in DX, CX
  236.     pop    ax            ;restore errorlevel
  237.     MOV    AH,4CH            ;Terminate process (errorlevel in AL)
  238.     INT    21H
  239.  
  240. Shut_Down    endp
  241.  
  242.  
  243. ;Call with DX=pointer to write buffer, CX=nr bytes to write.
  244. Write    proc    near
  245.     MOV    AH,40H            ;write to file/device
  246.     MOV    BX,1            ;to Std Out
  247.     INT    21H
  248.     RET
  249. Write    endp
  250.  
  251.  
  252. buff370    label    byte            ;read/write buffer beyond code
  253.  
  254. CSeg    ENDS
  255.     END    NoBit7
  256.